<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

include( dirname(__FILE__).'/j15comp.php');


if (ereg('index2.php',$_SERVER['REQUEST_URI'])) mosRedirect('index3.php?option=com_oscommerce');
if (ereg('index.php', $_SERVER['REQUEST_URI'])) mosRedirect('index3.php?option=com_oscommerce');

global $database;
$database->setQuery("Select * from #__osc_configuration where configuration_key='SHOW_GA'");
$result = $database->loadObjectList();
define('LIC_CODE_ECJC',  $result[0]->configuration_value);


function show($upgrade) {

$upgraded = ispaid();

if ($upgrade == 'newsubs' && $upgraded) {

return true;

}

if ($upgrade == 'newsubs' && !$upgraded) {
echo '<p><strong>Only Available in licenced version</strong></p>';
return false;
}



if ($upgrade == 'doajaxattrib' && $upgraded) {
global $pInfo;
?>
                <tr>
            <td colspan="2" class=contentheading><?php echo TEXT_PRODUCTS_SUBSCRIPTION; ?></td></tr>
            <tr><td colspan="2" class="maincol"><? include ("includes/subinc.php"); ?></td></tr>
        
                <!-- AJAX Attribute Manager  -->
                      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
                <tr>
                <td colspan="2" class=contentheading>
                <?php echo BOX_CATALOG_CATEGORIES_PRODUCTS_ATTRIBUTES; ?>
                </td></tr>
          <tr>
          	<td colspan="2"><?php require_once( DIR_WS_COMPONENT . 'attributeManager/includes/attributeManagerPlaceHolder.inc.php' )?></td>
          </tr>
          <?php

}elseif($upgrade == 'compbuild' && !$upgraded) {
mosRedirect("index3.php?option=com_oscommerce&osMod=paidonly");
}elseif($upgrade == 'suppliers' && !$upgraded) {
mosRedirect("index3.php?option=com_oscommerce&osMod=paidonly");
}elseif($upgrade == 'subscription_prefferances' && !$upgraded) {
mosRedirect("index3.php?option=com_oscommerce&osMod=paidonly");
}elseif($upgrade == 'auctions' && !$upgraded) {
mosRedirect("index3.php?option=com_oscommerce&osMod=paidonly");
}

}

function ispaid() {

$http_host = explode(':', $_SERVER['HTTP_HOST'] );
if ($http_host[0] == 'localhost' || $http_host[0] == '127.0.0.1'){
return true;
}

//secret words::: Important
$secret = 'ecjc';

//reverse gen the key:::
$keyarr = explode("-", LIC_CODE_ECJC);

$liccount =  count($keyarr);
if($liccount < 4){
//not a valid licence,
return false;
}else{
//ok there are 3 dashes, but are there 3 10 values

$keya =  strlen($keyarr[1]);
$keyb = strlen($keyarr[2]);
$keyc = strlen($keyarr[3]);
if ($keya == 10 && $keyb == 10 && $keyc == 10){
//ok length right
//dbl validation maybe soon 
return true;
}else{
return false;
}

}


//ok is it an upgrade?
//die($keyfin . '<br>' . LIC_CODE_ECJC);
return false;

}




   // Set the local configuration parameters - mainly for developers
    if (file_exists('components/com_oscommerce/includes/local/configure.php'))
      include('components/com_oscommerce/includes/local/configure.php');

  // Include application configuration parameters
    require('components/com_oscommerce/includes/configure.php');
   // For the contrib installer 
define('ESCOM_VERSION', 1);
define('JOSCOM_VERSION', 1);
define('DIR_FS_ADMIN_BACKUP',$mosConfig_absolute_path . '/administrator/components/com_oscommerce/backups/');
define('DIR_FS_ADMIN_INCLUDES', $mosConfig_absolute_path . '/administrator/components/com_oscommerce/includes/');
define('DIR_FS_ADMIN_LANGUAGES', $mosConfig_absolute_path . '/administrator/components/com_oscommerce/includes/languages/');
define('DIR_FS_ADMIN_CLASSES', $mosConfig_absolute_path . '/administrator/components/com_oscommerce/includes/classes/');
define('DIR_FS_ADMIN_FUNCTIONS',  $mosConfig_absolute_path . '/administrator/components/com_oscommerce/includes/functions/');
define('DIR_WS_ADMIN_ICONS', $mosConfig_absolute_path . '/administrator/components/com_oscommerce/images/icons/');

  define('MAX_PROD_ADMIN_SIDE', 30);
  // forward to oscommerce module for processing
  
  
  
  
  switch ($task) {
  case 'upgrade':
  $ver = $_REQUEST['ver'];
   require($mosConfig_absolute_path."/administrator/components/com_oscommerce/sql/".$ver."sql.php");
  mosRedirect('index3.php?option=com_oscommerce', 'Database Upgraded');
  break;
  default:
 
 
  //$osMod = mosGetParam( $_REQUEST, 'osMod', 'index' );
  
  
  if(isset($_POST['osMod'])){
  $osMod = $_POST['osMod'];
  }elseif(isset($_GET['osMod'])){
  $osMod = $_GET['osMod'];
  }else{
  $osMod = 'index';
  }
  
  if ($osMod == 'compbuild') {
  show('compbuild');
    
  }
  
  if ($osMod == 'suppliersadmin'){
  show('suppliers');
  }
  
  if ($osMod == 'subscription_prefferances'){
  show('subscription_prefferances');
  }
  
  if ($osMod == 'auctions'){
  show('auctions');
  }
  //echo $osMod;
  
  if ($osMod == 'index3' || $osMod == 'index2'){
  $osMod='index';
  include( 'components/com_oscommerce/index.php' );
  }else{
  
  include( 'components/com_oscommerce/' . $osMod . '.php' );
  //include( 'components/com_oscommerce/index.php' );
  }
  
  break;
}

?>
